<?php
/**
 * Created by PhpStorm.
 * User: moonlight
 * Date: 2015/6/14
 * Time: 14:43
 */

namespace Admin\Controller;


use Think\Controller;

class IndexController extends Controller{
    public function index(){
        $info = $this->isSession();
        //dump($info);
        if($info == 0){
           // dump('1');
            $this->login();
        }else{
          //  dump('2');
            $this->display('index');
        }
    }
    public function isSession(){
        $user_manage = array(
            'status'  => 0,//0未登录，1登录；
            //'value1'  => '注册',
            'value2'  => '登录',
            //'url1'    => U('User/register'),
            'url2'    => U('User/login'),
        );
        if(session('?manager_name')){
            $user_manage = array(
                'status'  => 1,//0未登录，1登录；
                'value1'  => session("manager_name"),
                'value2'  => '退出',
                'url1'    => U('User/userManage'),
                'url2'    => U('User/userExit'),
            );
        }
        $this->assign('user_manage',$user_manage);
        return $user_manage['status'];
    }
    public function login(){
        if(IS_POST){
            $data = I('post.');
            $result = D('User')->login($data);
            //dump('1');
            if($result){
                //dump('2');
                $this->index();
            }else{
                $this->error('登录失败',U('Index/login'),3);
            }
        }else{
            $this->display('login');
        }
    }
    public function userLists(){
        if($this->isSession()){
            $userLists = D('User')->getUserLists();
            $this->assign('userLists',$userLists);
            $this->display('userLists');
        }else{
            $this->error('请先登录',U('Index/login'),5);
        }
    }
    public function infoDelete(){
        $data = I('get.');
        //dump($data);die;
        $result = D('User')->infoDelete($data);
        if($result == 1){
            $this->userLists();
        }
        if($result == 2){
            $this->blogLists();
        }
    }
    public function blogLists(){
        if($this->isSession()){
            $blogLists = D('User')->getBlogLists();
            $this->assign('blogLists',$blogLists);
            $this->display('blogLists');
        }else{
            $this->error('请先登录',U('Index/login'),5);
        }
    }
}